<%@page import="java.io.File"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<%@ page import="java.util.*" %>
<html>

    <head>

        <link rel="stylesheet" href="resources/style.css" type="text/css"/>
        <link href='http://fonts.googleapis.com/css?family=Bevan' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>



        <title>Photo Uploader</title>

    </head>



    <body>
        <h1>The Photo Uploader</h1>



        <div class="box">
            <form action="UploadServlet" method="POST" enctype="multipart/form-data" >
                <div class="funny_text">Choose an image to upload</div>
                <input type="file" name="file" size="50" class="input" /> <br><br>

                <div class="funny_text">Any description?<br>

                    <textarea name="texta" rows="6" cols="75" class="funny_text2"></textarea> </div><br>
                <input type="submit" value="Upload File"/>
            </form>

            <%
                //Showing some actions notifications
                if (request.getParameter("up_status") != null) {
            %> <center><b style="color:#31B404;"> Congrats! Image successfully uploaded</b></center> <%        }
                if (request.getParameter("mod_candeled") != null) {
            %> <center><b style="color:#DF0101;"> Changes discarded</b></center> <%        }

            %>

            <br>


        </div>  






        <h2>Your gallery</h2>


        <%
            //  String webPath = request.getRequestURL().toString() ;

            List imageUrlList = new ArrayList();
            String pathToImages = getServletContext().getRealPath("WEB-INF/classes/uploaded_images/");

            File imageDir = new File(pathToImages);

            for (File imageFile : imageDir.listFiles()) {
                String imageFileName = imageFile.getName();
                // add this images name to the list we are building up  
                imageUrlList.add(imageFileName);
        %>
        <a href='javascript:void(0);' onclick="window.open('showimage.jsp?img=<%=imageFileName%>', 'View photo', 'width=800,height=400,left=200,top=100')"/> <img id="<%=imageFileName%>" height="200px" width="250px" src="image/<%=imageFileName%>" class="vignette"/>
    </a>
    <% }
    %>

    <br/> <br/>   <br/>   <br/>   <br/>   <br/>   <br/>
    <center><small>Web for WWWTechonologies. University of Thessaly.</small></center>

</body>
</html>